﻿using log4net;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;

namespace JobLibrary
{
    class Program
    {
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            HostFactory.Run(x =>
            {
                x.RunAsLocalSystem();

                x.SetDescription("SetDescription");
                x.SetDisplayName("SetDisplayName");
                x.SetServiceName("SetServiceName");

                x.Service(factory =>
                {
                    QuartzServer server = CreateServer();
                    server.Initialize();
                    return server;
                });
            });
        }


        private static readonly ILog logger = LogManager.GetLogger(typeof(Program));

        /// <summary>
        /// Creates a new instance of an Quartz.NET server core.
        /// </summary>
        /// <returns></returns>
        public static QuartzServer CreateServer()
        {
            string typeName = typeof(QuartzServer).AssemblyQualifiedName;

            Type t = Type.GetType(typeName, true);

            logger.Debug("Creating new instance of server type '" + typeName + "'");
            QuartzServer retValue = (QuartzServer)Activator.CreateInstance(t);
            logger.Debug("Instance successfully created");
            return retValue;
        }

    }
}                  
